<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/index' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item><a href="javascript:;">文章管理</a></el-breadcrumb-item>
      <el-breadcrumb-item>文章列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card
      class="box-card"
      style="margin-top:20px;"
    >
      <el-table
        :data="postlist"
        border
        style="width: 100%"
      >
        <el-table-column
          type="index"
          width="50"
        >

        </el-table-column>
        <el-table-column
          prop="title"
          label="标题"
        >
        </el-table-column>
        <el-table-column
          label="类型"
          width="80"
        >
          <template slot-scope="scope">
            {{scope.row.type==1?'文章':'视频'}}
          </template>
        </el-table-column>
        <el-table-column
          prop="user.nickname"
          label="作者"
          width="150"
        >
        </el-table-column>
        <el-table-column
          width="210"
          label="操作"
        >
          <template slot-scope="scope">
            <el-tooltip
              content="编辑"
              placement="top"
            >
              <el-button
                type="primary"
                icon="el-icon-edit"
                @click="$router.push({path:`postPublish/${scope.row.id}`})"
              ></el-button>
            </el-tooltip>
            <el-tooltip
              content="分享"
              placement="top"
            >
              <el-button
                type="success"
                icon="el-icon-share"
              ></el-button>
            </el-tooltip>
            <el-tooltip
              content="删除"
              placement="top"
            >
              <el-button
                type="danger"
                icon="el-icon-delete"
                @click="handleDelte(scope.$index, scope.row)"
              ></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageIndex"
        :page-sizes="[3, 5, 7, 9]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
import { getPost } from "@/api/post.js";
export default {
  data() {
    return {
      postlist: [],
      pageIndex: 1,
      pageSize: 3,
      total: 0,
    };
  },
  methods: {
    handleEdit(i, d) {
      console.log(i, d);
    },
    handleDelte(i, d) {
      console.log(i, d);
    },
    handleSizeChange(v) {
      this.pageSize = v;
      this.init();
    },
    handleCurrentChange(v) {
      this.pageIndex = v;
      this.init();
    },
    async init() {
      let res = await getPost({
        pageSize: this.pageSize,
        pageIndex: this.pageIndex,
      });
      this.postlist = res.data.data;
      this.total = res.data.total;
    },
  },
  mounted() {
    this.init();
  },
};
</script>

<style>
</style>